package com.dao;

import java.util.List;

import com.entity.GoodsType;
import com.util.Page;

public class MenbersDao extends BaseDAO {
	
	public boolean saveGoodsType(GoodsType goodsType){
		
		return this.saveObject(goodsType);
	}
	
	public List listGoodsType() throws Exception{
		return this.queryObject(GoodsType.class);
	}
	
	public GoodsType editGoodsType(String id) throws Exception{
		List<GoodsType> list = null;
		GoodsType goodsType = null;
		list = this.queryObject(GoodsType.class,"where :id=?",id);
		if(list != null && list.isEmpty()){
			goodsType =list.get(0);
		}
		return goodsType;
	}	
	
	/**
	 * 取一级菜单
	 * @return
	 * @throws Exception
	 */
	public List findTopNod() throws Exception{
		String sql  = "select * from goods_types where parentid=0";
		return this.findObjectBySql(GoodsType.class, sql);
	}
	
	/**
	 * 取二级菜单
	 * @return
	 */
	public List findTowNod(){
		String sql = " select * from goods_types where parentid  in (select id from goods_types where parentid=0)";
		return this.findObjectBySql(GoodsType.class, sql);
	}
	
	/**
	 * 取二级菜单
	 * @return
	 * @throws Exception 
	 */
	public List findParentGoodsTypeById(int id) throws Exception{
		return this.queryObject(GoodsType.class,"where parentid=?",id);
	}
	
	/**
	 * 取三级菜单
	 * @return
	 */
	public List findThreeNod(){
		String sql = " select * from goods_types where parentid  in (select id from goods_types where parentid  in (select id from goods_types where parentid=0))";
		return this.findObjectBySql(GoodsType.class, sql);
	}
	
	public boolean delGoodsType(){
		return false;
	}
	
	public boolean updateGoodsType(String sql){
		return this.executeUpdate(sql);
	}
	
	public boolean delGtypeById(){
		return false;
	}
	/**
	 * 按分页查询
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public Page findbyPage(Page page) throws Exception{
		return this.queryObjectForPage(GoodsType.class, page);
	}
}
